package com.logic.view

import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.logic.contract.DailyInventoryRfidContract
import com.logic.presenter.DailyInventoryRfidPresenter
import com.sinopec.basemodule.dialog.dfHint
import com.sinopec.basemodule.launchcontract.UHFDailyInventoryResultLaunch
import com.sinopec.basemodule.model.DailyInventoryApiRequestModel
import com.sinopec.basemodule.utils.ARouterManagerUtils
import com.sinopec.basemodule.utils.kotlin.annotation.Style
import com.sinopec.basemodule.utils.kotlin.bean.TextMoreStyle
import com.sinopec.basemodule.utils.kotlin.setMoreStyle
import kotlinx.android.synthetic.main.bm_a_uhf.*

/**
 * @author lwj
 * @ClassName: UhfDailyInventoryActivity
 * @Description: 日常盘库-rfid扫码界面
 */
@Route(path = ARouterManagerUtils.GOTO_UHF_DAILY_INVENTORY_ACTIVITY)
class UhfDailyInventoryActivity : BaseUhfActivity<DailyInventoryRfidPresenter>(
    "日常盘库扫码"
), DailyInventoryRfidContract.View {

    /**
     * 带出的参数
     */
    private val params by lazy {
        UHFDailyInventoryResultLaunch.getParams(this)
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        mPresenter = DailyInventoryRfidPresenter(this)
        //是否显示顶部查看编码布局
        ll_change_number.visibility = View.GONE
        ll_look.visibility= View.GONE

        tv_change_number.setMoreStyle(
            TextMoreStyle.builder(
                "当前包装规格："
            ).setTextColor(
                Color.parseColor("#002344")
            ).setTextStyle(
                Style.NORMAL
            ).build(),

            TextMoreStyle.builder("${params?.packSpecsTypeName}").setTextColor(
                Color.parseColor("#6e85f9")
            ).setTextStyle(Style.BOLD)
                .build(),
        )
    }

    override fun initEvent() {
        super.initEvent()

    }

    override fun onAccessRefreshList(
        sourceList: List<String>?,
        targetList: ArrayList<String>,
    ): Boolean {
        if (sourceList?.size == 0) {
            targetList.clear()
            return true
        }
        targetList.clear()
        if (sourceList != null && sourceList.isNotEmpty()) {
            for (i in sourceList.indices) {
                val operateTagMap = sourceList[i]
                targetList.add(operateTagMap)
            }
        }

        return true
    }

    override fun dispatchNextStep(mList: ArrayList<String>) {
        dfHint(buildString {
            append("本次共扫码<font color='#6e85f9'>${mList.size}</font>块，")
            append("是否确认盘库？")
        }) {
            if (it) {
                val requestModel = DailyInventoryApiRequestModel()
                requestModel.packSpecsTypeId = params?.packSpecsTypeId
                requestModel.palletCodes = mList
                mPresenter.confirmDailyInventory(requestModel)
            }
        }.show(supportFragmentManager, "")
    }
}